Type Class Instances for Type-Level Lambdas in Haskell
نویسندگان
چکیده
Haskell 2010 lacks flexibility in creating instances of type classes for type constructors with multiple type arguments. We would like to make the order of type arguments to a type constructor irrelevant to how type class instances can be specified. None of the currently available techniques in Haskell allows to do this in a satisfactory way. To flexibly create type-class instances we have added the concept of type-level lambdas as anonymous type synonyms to Haskell. As higher-order unification of lambda terms in general is undecidable, we take a conservative approach to equality between type-level lambdas. We propose a number of small changes to the constraint solver that will allow type-level lambdas to be used in type class instances. We show that this satisfies our goal, while having only minor impact on existing Haskell code.
منابع مشابه
Refinement Reflection (or, how to turn your favorite language into a proof assistant using SMT)
Refinement Reflection turns your favorite programming language into a proof assistant by reflecting the code implementing a userdefined function into the function’s (output) refinement type. As a consequence, at uses of the function, the function definition is unfolded into the refinement logic in a precise, predictable and most importantly, programmer controllable way. In the logic, we encode ...
متن کاملNamed Instances for Haskell Type Classes
Although the functional programming language Haskell has a powerful type class system, users frequently run into situations where they would like to be able to define or adapt instances of type classes only after the remainder of a component has been produced. However, Haskell’s type class system essentially only allows late binding of type class constraints on free type variables, and not on u...
متن کاملAnti-Unification with Type Classes
The anti-unification problem is that of finding the most specific pattern of two terms. While dual to the unification problem, anti-unification has rarely been considered at the level of types. In this paper, we present an algorithm to compute the least general type of two types in Haskell, using the logic programming power of type classes. That is, we define a type class for which the type cla...
متن کاملExplicitly Typed Exceptions for Haskell
We describe a monad for checked, explicitly typed exceptions, which provides as a simple Haskell library what for other languages is a native feature. Multi parameter type classes and overlapping instances are the only essential extensions to Haskell 98 required.
متن کاملObjects to Unify Type Classes and GADTs
We propose an Haskell-like language with the goal of unifying type classes and generalized algebraic datatypes (GADTs) into a single class construct. We treat classes as first-class types and we use objects (instead of type class instances and data constructors) to define the values of those classes. We recover the ability to define functions by pattern matching by using sealed classes. The res...
متن کامل